import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;


public class SortingFrameWork {
	private SorteerAlgoritmen sorteerAlgoritmen;
	private RandomDataGenerator rndDataGen; 
	

	public SortingFrameWork(String fileName){
		rndDataGen = new RandomDataGenerator();
		sorteerAlgoritmen = new SorteerAlgoritmen();
		int[] testListSizes = testListSizes();
		
		for (int i=0; i<testListSizes.length; i++){
			Integer[] tmpList = rndDataGen.getRandomData(testListSizes[i]);
			
			//sorteerAlgoritmen.insertionSort(Arrays.copyOf(tmpList, tmpList.length));
			sorteerAlgoritmen.quickSort(Arrays.copyOf(tmpList, tmpList.length));
			sorteerAlgoritmen.mergeSort(Arrays.copyOf(tmpList, tmpList.length));
			System.out.println();
		}
	}
	
	public int[] testListSizes(){
		int[] tmpList = new int[8];
		tmpList[0]=10000;
		tmpList[1]=20000;
		tmpList[2]=40000;
		tmpList[3]=80000;
		tmpList[4]=160000;
		tmpList[5]=320000;
		tmpList[6]=640000;
		tmpList[7]=640000;
		return tmpList;
	}
		
	public ArrayList<String> readDataFromFile(String fileName){
		ArrayList<String> tmpData = new ArrayList<String>();
		try {
			BufferedReader br = new BufferedReader(new FileReader(fileName));
			String line;
			
			while ((line = br.readLine()) != null){
				for (String s : line.split(",")){
					if (!s.equals("")){
						tmpData.add(s);
					}
				}
				
			}

			return tmpData;
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return tmpData;
	}
	
	
	public Integer[] toIntArray(ArrayList<String> list){
		int teller = 0;
		if (!list.isEmpty()){	
				Integer[] tmpListInt = new Integer[list.size()];
				for (String s : list){
					tmpListInt[teller] = Integer.parseInt(s);
					teller ++;
				}
				return tmpListInt;
		}
		return null;
	}
	
	public String[] toStringArray(ArrayList<String> list){
		int teller = 0;
		if (!list.isEmpty()){	
			String[] tmpListInt = new String[list.size()];
			for (String s : list){
				tmpListInt[teller] = s;
				teller++;
			}
			return tmpListInt;
		}
	return null;
	}
	
	public boolean hasInts(ArrayList<String> data){
		try {
			Integer.parseInt(data.get(0));
			return true;
		} catch(NumberFormatException e){
			return false;
		}
	}
	
}
